package yyy.ab.modules.security.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 页面登出处理
 */
@Slf4j
public class AbLogoutHandler implements LogoutHandler {

    private String redirectUrl;

    public AbLogoutHandler(String redirectUrl) {
        this.redirectUrl = redirectUrl;
    }

    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        response.setCharacterEncoding("utf-8");
        try {
            response.sendRedirect(redirectUrl);
        } catch (IOException e) {
            log.error("user logout exception:" + e);
        }
    }
}
